﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//Write a program that exchanges bits 3, 4 and 5 with bits 24, 25 and 26 of given 32-bit unsigned integer.

namespace _14SwitchingBitsFormula
{
    class _14SwitchingBitsFormula
    {
        static void Main(string[] args)
        {

            Console.Write("Enter a positive integer:");
            string number = Console.ReadLine();
            uint n = uint.Parse(number);
            uint bit3 = ((n >> 3) & 1);
            uint bit4 = ((n >> 4) & 1);
            uint bit5 = ((n >> 5) & 1);
            uint bit24 = (n >> 24) & 1;
            uint bit25 = (n >> 25) & 1;
            uint bit26 = (n >> 26) & 1;

            Console.WriteLine("Before: {0}", Convert.ToString(n, 2).PadLeft(32, '0'));

            if (bit3 == 0)
            {
                n = n & (~((uint)1 << 24));
            }
            else
            {
                n = n | (1 << 24);
            }
            //---------------------------------------
            if (bit4 == 0)
            {
                n = n & (~((uint)1 << 25));
            }
            else
            {
                n = n | (1 << 25);
            }
            //---------------------------------------
            if (bit5 == 0)
            {
                n = n & (~((uint)1 << 26));
            }
            else
            {
                n = n | (1 << 26);
            }
            //---------------------------------------
            if (bit24 == 0)
            {
                n = n & (~((uint)1 << 3));
            }
            else
            {
                n = n | (1 << 3);
            }
            //---------------------------------------
            if (bit25 == 0)
            {
                n = n & (~((uint)1 << 4));
            }
            else
            {
                n = n | (1 << 4);
            }
            //---------------------------------------
            if (bit26 == 0)
            {
                n = n & (~((uint)1 << 5));
            }
            else
            {
                n = n | (1 << 5);
            }

            Console.WriteLine("After:  {0}", Convert.ToString(n, 2).PadLeft(32, '0'));
        }
    }
}
